/*
	Author: Samuel Thacker
	Description: A program file that gives commands associated with the dummy structures.
	Revisions:
		2012/1/26 - Creation of this program file.
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "DummyStructure.h"

dll * newList() /*Creates a dummy list.*/
	{
	dll * l;
	if(!( l = (dll *)malloc(sizeof(dll))))
		exit(1); /*If there is no memory, exit*/
	l->first = NULL;
	l->last = NULL;
	l->size = 0;
	return l;
	}

void addElement(dll * l, char * s1, char * s2, char * s3, char * s4) /*Appends a dummy element to a dummy list.*/
	{
	de * e;
	if(!( e = (de *)malloc(sizeof(de))))
		exit(1); /*If there is no memory, exit*/

	if(l->size == 0) /*If first element is being added.*/
		{
		l->first = e;
		}
	else
		{
		l->last->next = e;
		}
	e->next = NULL;
	l->last = e;
	if(!(e->str1 = (char *)malloc(sizeof(char) * (strlen(s1)+1))))
		exit(1); /*If there is no memory, exit*/
	if(!( e->str2 = (char *)malloc(sizeof(char) * (strlen(s2)+1))))
		exit(1); /*If there is no memory, exit*/
	if(!( e->str3 = (char *)malloc(sizeof(char) * (strlen(s3)+1))))
		exit(1); /*If there is no memory, exit*/
	if(!( e->str4 = (char *)malloc(sizeof(char) * (strlen(s4)+1))))
		exit(1); /*If there is no memory, exit*/
	strcpy(e->str1,s1);
	strcpy(e->str2,s2);
	strcpy(e->str3,s3);
	strcpy(e->str4,s4);
	l->size++;
	}

void delList(dll * l) /*Deletes the dummy list and all its elements.*/
	{
	de * a, * b;
	a = l->first;
	while(a) /*Stops at the end of the list (when a == NULL).*/
		{
		b = a->next;
		free(a->str1);
		free(a->str2);
		free(a->str3);
		free(a->str4);
		free(a);
		a = b;
		}
	free(l);
	}
/*EOF*/
